package com.boatAnchorAssistant.service.controller.web;

import com.boatAnchorAssistant.pojo.param.iTable.*;
import com.boatAnchorAssistant.pojo.vo.iTable.*;
import com.boatAnchorAssistant.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.List;

/**
 * web/表单
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/iTable/web")
public class ITableWebController {

    private final ITableService service;

    public ITableWebController(ITableService service) {
        this.service = service;
    }


    /**
     * 创建表单
     *
     * @param param
     * @return
     */
    @PostMapping("/createITable")
    public ApiResult createITable(@RequestBody @Valid CreateITableParam param) {
        service.createITable(param);
        return ApiResult.ok();
    }


    /**
     * 修改表单
     *
     * @param param
     */
    @PutMapping("/editITable")
    public ApiResult editITable(@RequestBody @Valid EditITableParam param) {
        service.editITable(param);
        return ApiResult.ok();
    }

    /**
     * 移除表单
     *
     * @param id
     */
    @DeleteMapping("/removeITable")
    public ApiResult removeITable(@RequestParam("id") Long id) {
        service.removeITable(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用表单
     *
     * @param id
     */
    @GetMapping("/enabledITable")
    public ApiResult enabledITable(@RequestParam("id") Long id) {
        service.enabledITable(id);
        return ApiResult.ok();
    }

    /**
     * 获取表单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getITable")
    public ApiResult<GetITableVo> getITable(@RequestParam("id") Long id) {
        GetITableVo vo = service.getITable(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取表单列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getITableList")
    public ApiResult<PageResult<GetITableListVo>> getITableList(@RequestBody GetITableListParam param) {
        PageResult<GetITableListVo> result = service.getITableList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取表单下拉列表
     *
     * @return
     */
    @PostMapping("/getITableDownList")
    public ApiResult<List<GetITableDownListVo>> getITableDownList(@RequestBody(required = false) @Valid GetITableDownListParam param) {
        List<GetITableDownListVo> list = service.getITableDownList(param);
        return ApiResult.ok(list);
    }


}

